|
|
|
|
|
|
|
Figure 11.2
Parametric spiral, Bowditch curve, and cycloid. |
|
|
|
|
|
|
|
|
If the DrawCurve routine were good for drawing nothing but circles, it would not be very useful. Visual Basic's Circle routine draws smooth circles more quickly and easily. There are two reasons the DrawCurve subroutine is important. First, it works for many other kinds of parametric curves. |
|
|
|
|
|
|
|
|
Figure 11.2 shows three other parametric curves. A program can draw all three of these curves using the same DrawCurve subroutine. Only the parametric functions X and Y need to change. Table 11.1 lists the parametric equations and the values covered by t for these curves, as well as the name of the example program that displays them. |
|
|
|
|
|
|
|
|
The second reason the DrawCurve subroutine is important is that it turns a set of parametric equations into a series of points along a curve. Before you connect the points with lines, you can perform actions on the points to transform the curve. |
|
|
|
|
|
|
|
|
For example, if you multiply the values returned for X(t) by 2 before you draw the points, the curve is stretched by a factor of two in the X direction. The following code draws a circle scaled in both the X and Y directions. |
|
|
|
 |
|
|
|
|
' Draw the curve on the indicated picture box
' scaled. Private Sub DrawCurve(ByVal pic As PictureBox, _
ByVal start_t As Single, ByVal stop_t As Single, _
ByVal dt As Single, _
ByVal x_scale As Single, ByVal y_scale As Single)
Dim cx As Single
Dim cy As Single
Dim t As Single
cx = pic.ScaleLeft + pic.ScaleWidth / 2
cy = pic.ScaleTop + pic.ScaleHeight / 2
pic.Cls
pic.CurrentX = cx + x_scale * X(start_t)
pic.CurrentY = cy + y_scale * Y(start_t)
t = start_t + dt
Do While t < stop_t |
|
|
|
|
|